// 本组件是收入类合同的
<template>
  <div>
    <el-table :border="false" :data="tableList" class="new-table-style">
      <el-table-column align="left" label="事项类型">
        <template slot-scope="scope">
          <span>{{ getChargeItemNmae(scope.row.chargeItemKey) }}</span>
        </template>
      </el-table-column>

      <el-table-column align="center" label="事项说明" prop="fundsDesc"></el-table-column>
      <el-table-column align="center" label="合同金额" width="140">
        <template slot-scope="scope">
          <span>{{ scope.row.fundsAmount | moneyFilter }}</span>
        </template>
      </el-table-column>
      <el-table-column align="center" label="相关设备" prop="assetName"></el-table-column>
      <el-table-column align="center" label="相关设施" prop="stationName"></el-table-column>

      <el-table-column v-if="isEdit" align="center" fixed="right" label="操作" width="80">
        <template slot-scope="scope">
          <el-button icon="el-icon-edit" class="normal-btn" size="mini" type="text" @click="editItem(scope.row)"></el-button>
          <el-button icon="el-icon-delete" class="normal-btn color-red" size="mini" type="text" @click="deleteItem(scope.$index)"></el-button>
        </template>
      </el-table-column>
    </el-table>
  </div>
</template>

<script>
  import Bus from '@js/bus.js';
  import { askDialog } from '@/pages/limit/assets/util';
  import { apiPaysonList } from '../../../../api/contract';

  export default {
    props: {
      contractType: {
        type: String,
        default: '',
      },
      isEdit: {
        type: Boolean,
        default: true,
      },
      tableList: {
        type: Array,
        default: () => {
          return [];
        },
      },
    },

    data() {
      return {
        chargeItemList: [],
      };
    },

    mounted() {
      this.getChargeItemList();
    },

    methods: {
      editItem(costItem) {
        let row = this.lodash.cloneDeep(costItem);
        Bus.$emit('costItem', row);
      },

      deleteItem(index) {
        askDialog('确认删除？', async () => {
          this.$emit('deleteItem', index);
        });
      },

      //事项类型
      async getChargeItemList(filedName) {
        let res = await apiPaysonList({ contractType: this.contractType });
        this.chargeItemList = res.rows || [];
      },

      getChargeItemNmae(key) {
        let target = this.chargeItemList.find(item => item.chargeItemKey == key);
        return target ? target.chargeItemAliasName : '';
      },
    },
  };
</script>

<style lang="scss" scoped></style>
